package com.example.societiesSystem.controller;


import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.societiesSystem.common.R;
import com.example.societiesSystem.entity.Activities;
import com.example.societiesSystem.entity.Activities;
import com.example.societiesSystem.service.IActivitiesService;
import com.example.societiesSystem.service.ITeamsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 社团活动信息表 前端控制器
 * </p>
 *
 * @author 周欢
 * @since 2025-05-27
 */
@Api(tags = "社团活动信息表 前端控制器")
@CrossOrigin
@RestController
@RequestMapping("/activities")
public class ActivitiesController {
    
    @Resource
    private IActivitiesService activitiesService;

    @Resource
    private ITeamsService teamsService;


    @ApiOperation(value = "分页查询社团活动信息")
    @GetMapping("/page")
    public R pageAll(@RequestParam("pageIndex") Long pageIndex
            , @RequestParam("pageSize") Long pageSize
            , @RequestParam(value = "token", required = false) Long token
            , @RequestParam(value = "teamName", required = false) String teamName
            , @RequestParam(value = "activeName", required = false) String activeName)
    {
        return R.data(activitiesService.pageAll(pageIndex,pageSize,token,teamName,activeName));
    }

    @ApiOperation(value = "查询所有社团活动信息")
    @GetMapping("/all")
    public R getAll() {
        return R.data(activitiesService.getBaseMapper().selectList(null));
    }

    @ApiOperation(value = "社团活动信息添加")
    @PostMapping("/add")
    public R add(@RequestBody Activities activities) {
        activities.setTeamName(teamsService.getNameById(Long.valueOf(activities.getTeamId())));
        return R.data(activitiesService.save(activities));
    }

    @ApiOperation(value = "社团活动信息修改")
    @PostMapping("/upd")
    public R upd(@RequestBody Activities activities) {
        return R.data(activitiesService.updateById(activities));
    }

    @ApiOperation(value = "社团活动信息删除")
    @PostMapping("/del")
    public R del(@RequestBody Activities activities) {
        return R.data(activitiesService.removeById(activities));
    }
}
